package cn.edu.xmu.datamining.tangzk.mralgos.pagerank;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.WritableComparable;

public class PageRankNodeKeyWritable implements
		WritableComparable<PageRankNodeKeyWritable> {

	private int id;
	private int type; // 0 -> structure info, 1 -> pagerank value

	public PageRankNodeKeyWritable() {

	}

	public PageRankNodeKeyWritable(int id, int type) {
		this.id = id;
		this.type = type;
	}

	@Override
	public void write(DataOutput out) throws IOException {
		out.writeInt(id);
		out.writeInt(type);
	}

	@Override
	public void readFields(DataInput in) throws IOException {
		this.id = in.readInt();
	}

	@Override
	public int compareTo(PageRankNodeKeyWritable o) {
		if (this.id != o.id) {
			return this.id - o.id;
		} else {
			return this.type - o.type;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof PageRankNodeKeyWritable)) {
			return false;
		}
		PageRankNodeKeyWritable o = (PageRankNodeKeyWritable) obj;
		if (this.id != o.id) {
			return false;
		} else {
			return this.type == o.type;
		}
	}

	@Override
	public int hashCode() {
		return this.id * 31 + this.type;
	}

	@Override
	public String toString() {
		return this.id + ", " + this.type;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

}
